#include "AnimationSequence.h"

using namespace game_engine::components;
using namespace game_engine::data_format;
using namespace game_engine::utils;

///////////////////////////////////////////////////////////////////////////////
// Constructors and Destructors
///////////////////////////////////////////////////////////////////////////////

AnimationSequence::AnimationSequence(void)
    : frameCount()
{
    frames.clear();
    clipRegion.clear();
    timeout.clear();
}

AnimationSequence::AnimationSequence(const FLOAT32 frameWidth,
                                     const FLOAT32 frameHeight,
                                     const vector<FrameInfo> &f, 
                                     const INT32 textureWidth)
    : frames(f)
{
    frameCount = frames.size();
    INT32 duration = 0;
	for(INT32 i=0; i<frameCount; i++)
    {
        //INT32 idFrame = frames[i].getId();
        //INT32 x = static_cast<INT32>((idFrame * frameWidth)) % textureWidth;
		//INT32 row = (( idFrame * frameWidth ) - x) / textureWidth;
        //INT32 y = row * frameHeight;
        //clipRegion.push_back(Rect(x, y, frameHeight, frameWidth));
        Point c = frames[i].getCoord();
        clipRegion.push_back(Rect(c.getX(), c.getY(), frameHeight, frameWidth));

        // Calculate the timeout of each frame in the sequence
        duration += frames[i].getDuration();
        timeout.push_back(duration);
	}
}

AnimationSequence::~AnimationSequence(void)
{
}

///////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////

const INT32 AnimationSequence::getFrameCount(void) const
{
    return frameCount;
}

const Rect& AnimationSequence::getClipRegion(const INT32 idFrame) const
{
    return clipRegion[idFrame];
}

const FrameInfo& AnimationSequence::getFrameInfo(const INT32 idFrame) const
{
    return frames[idFrame];
}

const INT32 AnimationSequence::getTimeout(const INT32 idFrame) const
{
    return timeout[idFrame];
}
